
<template>
	<view class="">
		<view class="header_background">
			<image src="../../static/images/bl.png" mode=""></image>
		</view>
		<view class="userMessage">
			<view class="common_block">
				<view style="padding: 0 30upx;">
					<view class="flex_layout">
						<view class="left_img">
							<image :src="user.avatar?user.avatar:'../../static/images/user.png'" mode=""></image>
							<view class="sexImg">
								<image src="../../static/images/sex1.png" mode=""></image>
							</view>
						</view>
						<view class="right_text">
							<view class="">{{user.nickname?user.nickname:'未登录'}}</view>
							<text>{{user.bio?user.bio:'这个人很懒，什么也没写'}}</text>
						</view>
					</view>
					<view class="operate_btn flex_layout">
						<view class="edit_code" @click="profile">
							<image src="../../static/images/operate1.png" mode=""></image>
							<text>门店信息</text>
						</view>
						<block v-if="myClinicInfo.user_type==1 || myClinicInfo.user_type==2">
							<view class="erect_position"></view>
							<view class="edit_code" @click="erweima">
								<image src="../../static/images/operate3.png" mode=""></image>
								<text>门店二维码</text>
							</view>
						</block>
						<view class="erect_position"></view>
						<view class="edit_code" @click="qrcode">
							<image src="../../static/images/operate2.png" mode=""></image>
							<text>扫一扫</text>
						</view>
					</view>
				</view>
			</view>
			<view class="common_block">
				<view class="manageData_title">我的管理数据</view>
				<view class="manageData_list flex_layout">
					<block v-if="myClinicInfo.user_type==1">
						<view class="manageData_text" @click="yuangong">
							<view>{{myClinicInfo.num.staff}}</view>
							<text>员工</text>
						</view>
					</block>
					
					<view class="manageData_text" @click="order">
						<view>{{myClinicInfo.num.order}}</view>
						<text>订单</text>
					</view>
				</view>
			</view>
			<view class="common_block footer_common_block">
				<view class="menu_list">
					<view class="menu_item" @click="yuangong" v-if="myClinicInfo.user_type==1"><image src="../../static/images/user3.png" mode="" ></image>员工管理</view>				
					<view class="menu_item" @click="order"><image src="../../static/images/user2.png" mode=""></image>订单管理</view>
					<view class="menu_item" @click="password"  v-if="myClinicInfo.user_type==1"><image src="../../static/images/password.png" mode=""></image>修改密码</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
			// 用户信息,
			user: this.$common.userInfo(),
			myClinicInfo:{
				num:{
					staff:'-',
					appointment:'-',
					order:'-'
				},
				user_type:'',
				qrcodeimage:''
			},
			clinic_id:'',
			name:'',
			qrcodeimage:''
			}
		},
		onLoad() {
		},
		mounted() {
			_this= this;
		},
		onShow() {
			this.user = this.$common.userInfo();
			if (this.user) {
				//console.log("this.user: ",this.user);
				this.$common.refreshUser(res => {
					if(this.user.avatar.indexOf("data:") != -1){
						var cavatar='/images/user.png';
						this.user.avatar=cavatar;
					}
				})
			}else{
				this.$common.toLogin();
			}
			//门店个人中心信息
			this.getMyClinicInfo();
		},
		methods: {
			//getMyClinicInfo
			//门店个人中心+用户+数据
			getMyClinicInfo:function(){
				var that=this;
				this.$common.loadToShow('努力加载中...')
				this.$api.getMyClinicInfo(
				    {},
					res => {
						this.$common.loadToHide();
						if (res.code == 1) {
							that.myClinicInfo=res.data
							that.clinic_id=res.data.id;
							console.log("that.clinic_id: ",that.clinic_id);
						}
						if (res.code == 0) {
							that.$common.errorToShow(res.msg,function(){
								that.$common.navigateTo('/index/index');
							})
						}
					}
				)
			},
			
			qrcode: function(){
				var that=this;
				uni.scanCode({
				    success: function (res) {
							var path='/'+res.path
							uni.navigateTo({
								url:path,
								success(res) {
									console.log(res);
								}
							})
				    }
				});
			},
			profile: function(){
				uni.navigateTo({
					url:'editMessage?clinic_id='+this.clinic_id
				})
			},
			erweima: function(){
				var that=this;
				var name=that.myClinicInfo.name
				var qrcodeimage=that.myClinicInfo.qrcodeimage
				uni.navigateTo({
					url:'erweima?name='+name+'&qrcodeimage='+qrcodeimage
				})
			},
			yuyue: function(){
				uni.navigateTo({
					url:'../index/myyuyue?clinic_id='+this.clinic_id+'&type=2'
				})
			},
			order: function(){
				uni.navigateTo({
					url:'../order/order?clinic_id='+this.clinic_id
				})
			},
			yuangong: function(){
				uni.navigateTo({
					url:'personal?clinic_id='+this.clinic_id
				})
			},
			
			password: function(){
				uni.navigateTo({
					url:'password'
				})
			}
		}
	}	
</script>

<style>
	@import url('../../common/common.css');
	page{background: #f8f8f8;}
	.flex_layout{display: flex; align-items: center; flex-wrap: wrap;}
	.header_background{position: relative; width: 100%; height: 220upx; background: #2562a1; z-index: -1;}
	.header_background image{position: absolute; display: block; left: 0; bottom: 0; height: 70upx; width: 100%;}
	.userMessage{width: 690upx; margin: -160upx auto 0;}
	.common_block{background: #fff; border-radius: 10px; padding: 30upx 0; margin-bottom: 20upx;}
	.left_img{position: relative; width: 114upx; height: 114upx;}
	.left_img>image{display: block; width: 114upx; height: 114upx; border-radius: 50%;}
	.sexImg{position: absolute; bottom: 10upx; right: 0; height: 30upx; width: 48upx; border-radius: 30upx; background: #2562a1; display: flex; align-items: center; justify-content: center;}
	.sexImg image{display: block; width: 20upx; height: 21upx;}
	.right_text{padding-left: 30upx;}
	.right_text view{color: #333333; font-size: 30upx;}
	.right_text text{color: #999; font-size: 24upx; margin-top: 20upx; display: block;}
	.operate_btn{background: #e8f3ff; justify-content: space-around; height: 60upx; margin-top: 30upx; margin-bottom: 10upx;}
	.erect_position{height: 36upx; width: 1px; background: #2562a1;}
	.edit_code{display: flex; align-items: center; justify-content: center;}
	.edit_code image{width: 30upx; height: 30upx; margin-right: 20upx;}
	.edit_code text{color: #2562a1; font-size: 24upx;}
	.manageData_title{color: #333; font-size: 30upx; padding: 0 30upx 20upx; border-bottom: 1px solid #f2f2f2;}
	.manageData_list{padding: 0 30upx; justify-content: space-around;}
	.manageData_text{padding: 30upx 30upx 0;}
	.manageData_text view{text-align: center; color: #333; font-size: 30upx;}
	.manageData_text text{display: block; text-align: center; font-size: 24upx; color: #666; margin-top: 10upx;}
	.menu_item{padding: 50upx 30upx; border-bottom: 1px solid #f8f8f8; display: flex; align-items: center; color: #333; font-size: 30upx;}
	.menu_item image{width: 36upx; height: 36upx; display: block; margin-right: 30upx;}
	.menu_item:last-child{border-bottom: none;}
	
	.footer_common_block{padding: 0;}
</style>